Skip to content

Move to bufio reader to support larger tokens #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 6, 2025

Conversation

davissp14
Copy link
Contributor

Works to address: #272

Comment on lines 60 to 68
line, err := reader.ReadBytes('\n')
if err != nil {
// EOF is expected, so don't log it
if err != io.EOF {
log.Printf("reader error: %v", err)
}
break
}
m.WriteLine(proc, line)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the docs, line may be non-empty even in case of an error (e.g. if the last output line is not terminated by \n), so may be worth piping it through regardless:

Suggested change
line, err := reader.ReadBytes('\n')
if err != nil {
// EOF is expected, so don't log it
if err != io.EOF {
log.Printf("reader error: %v", err)
}
break
}
m.WriteLine(proc, line)
line, err := reader.ReadBytes('\n')
if len(line) > 0 {
m.WriteLine(proc, line)
}
if err != nil {
// EOF is expected, so don't log it
if err != io.EOF {
log.Printf("reader error: %v", err)
}
break
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And one more thing, ReadBytes keeps the terminator in the returned line, so WriteLine may need to account for it:

 	buf.WriteString("\033[0m | ")
 
 	buf.Write(p)
-	buf.WriteByte('\n')
+	if p[len(p)-1] != '\n' {
+		buf.WriteByte('\n')
+	}
 
 	m.mutex.Lock()
 	defer m.mutex.Unlock()

@davissp14 davissp14 requested a review from immerrr February 6, 2025 17:13
Copy link

@immerrr immerrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@davissp14 davissp14 merged commit 5a04d2b into master Feb 6, 2025
6 checks passed
@davissp14 davissp14 deleted the supervisor-output-fix branch February 6, 2025 18:09
@davissp14
Copy link
Contributor Author

@immerrr Thanks for the assist!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants